//
// Created by root on 2020/4/15.
//

#ifndef HEATBEATSERVER_USER_H
#define HEATBEATSERVER_USER_H

#include <memory>

#include <muduo/net/TcpConnection.h>

/**
 * 用来管理对应的客户端
 */
class CUser {
public:
    typedef std::weak_ptr<muduo::net::TcpConnection> TcpConnectionWeakPtr;

public:
    CUser();
    CUser(muduo::net::TcpConnectionPtr pConn, const std::string _sConnName);
    muduo::net::TcpConnectionPtr GetSharedConnPtr() { return m_pTcpConnection.lock(); }

    std::string id() const { return m_sConnId; }

    /**
     * 该连接是否有效
     * @return true：有效 false：无效
     */
    bool IsValid() { return m_sId.size() != 0; }

    bool IsLogined() { return m_bLogined; }
    void SetLogined(bool _bLogined) { m_bLogined = _bLogined; }

private:
    TcpConnectionWeakPtr m_pTcpConnection;  ///< 客户端连接对象
    std::string m_sConnId;    ///< 客户端的连接名称
    std::string m_sId;        ///< 存储在数据库的逻辑Id
    bool m_bLogined;          ///< 是否登陆 true:已登陆 false:未登录
};


#endif //HEATBEATSERVER_USER_H
